using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace Crux.Core.Mvc.Filters;
/// <summary>
/// GlobalExceptionFilter
/// </summary>
public class GlobalExceptionFilter(ILogger<GlobalExceptionFilter> logger)
    : IExceptionFilter
{
    private readonly ILogger<GlobalExceptionFilter> _logger = logger;
    /// <inheritdoc/>
    public void OnException(ExceptionContext context)
    {
        if (context.HttpContext.RequestAborted.IsCancellationRequested) return;

        var other = new OtherExceptionHandler(_logger);
        var locked = new LockedExceptionHandler(other);
        var conflict = new ConflictExceptionHandler(locked);
        var forbidden = new ForbiddenExceptionHandler(conflict);
        var unauthorized = new UnauthorizedExceptionHandler(forbidden);
        var resourceNotFound = new ResourceNotFoundExceptionHandler(unauthorized);
        var badRequest = new BadRequestExceptionHandler(resourceNotFound);

        badRequest.Next(context);
    }


}